package com.maycurobj;

import com.alibaba.fastjson.JSONObject;

import com.maycurobj.domain.maycurDTO.CarmileageDTO;
import com.maycurobj.service.http.MaycurApiService;
import com.maycurobj.util.NormalUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;

/**
 * 里程补贴测试
 */

@SpringBootTest
class CarmileageForDemo {
    //
    @Autowired
    private MaycurApiService maycurApiService;

    //里程补贴编码    ECA136206775379571727
    @Test
    public void interfaceMainSave(){
        String _timestamp="2025-01-13 08:38:08";
        //创建数据
        CarmileageDTO myHomeDto=myHomeDTO("END","2025-01-13 17:38:08");
        CarmileageDTO dto = new CarmileageDTO();
        dto.setAddress("浙江省杭州市余杭区文一西路824号");
        dto.setLongitude("120.09266");
        dto.setLatitude("30.14064");
        dto.setTimeStamp(NormalUtil.dateTimeToLong(_timestamp));
        dto.setPointType("VIA");
        dto.setCarAllowanceCode("ECA136206775379571727");
        dto.setEmployeeId("ZJBS001273");
//        dto.setDistance(22.0);
        try {

            executeQuest(myHomeDto);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void interfaceMainList(){
        JSONObject reqJson=new JSONObject();
        reqJson.put("pageNo", 1);
        reqJson.put("pageSize", 30);
        reqJson.put("expensed", false);
        reqJson.put("startTime", NormalUtil.dateToLong("2025-01-01"));
        reqJson.put("endTime", NormalUtil.dateToLong("2025-01-31"));
        reqJson.put("employeeIdList", Arrays.asList("ZJBS001273"));
        JSONObject tokenInfo = maycurApiService.getToken();
        String requestUrl=String.format("%s%s", "https://ng.maycur.com", "/api/openapi/carmileage/list");
        String ret = null;
        try {
            ret = maycurApiService.doPostForMaycur(requestUrl, tokenInfo, JSONObject.toJSONString(reqJson));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println("打印结果：" + JSONObject.toJSONString(ret));
    }

    private void executeQuest(CarmileageDTO entity) throws Exception {
        JSONObject tokenInfo = maycurApiService.getToken();
        String requestUrl=String.format("%s%s", "https://ng.maycur.com", "/api/openapi/carmileage/point/save");
        String ret = maycurApiService.doPostForMaycur(requestUrl, tokenInfo, JSONObject.toJSONString(entity));
        System.out.println("打印结果：" + JSONObject.toJSONString(ret));
    }

    private CarmileageDTO myHomeDTO(String pointType,String timeStamp){
        CarmileageDTO dto = new CarmileageDTO();
        dto.setAddress("浙江省杭州市余杭区文一西路824号");
        dto.setLongitude("120.05104");
        dto.setLatitude("30.28997");
        dto.setTimeStamp(NormalUtil.dateTimeToLong(timeStamp));
        dto.setPointType(pointType);
        dto.setCarAllowanceCode("ECA136206775379571727");
        dto.setEmployeeId("ZJBS001273");
        dto.setDistance(22.0);
        return dto;
    }

}
